import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;


public class Start {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner inputScanner = new Scanner (System.in);
		FileIOMerge dictIO = null;

//		if (args.length == 0) {
//			System.out.println("Please enter a file to use as dictionary");
//			dictIO = new FileIO2(inputScanner.next());
//		}else {
			dictIO = new FileIOMerge(args[0]);//}

		Map<String,ArrayList<HashMap<String,String>>> dictionaryMap = dictIO.getA();;


		
		while (inputScanner.hasNext()){
			System.out.println("Commands are search and ls then a space then a letter of the alphabet");
			String temp = inputScanner.next();
			if (temp.equalsIgnoreCase("ls")){
				if (dictionaryMap == null) System.out.println("Dictionary Empty");
				System.out.println(dictionaryMap.get(inputScanner.next()));
				System.out.println("The left hand field is the reordered word, right of the equals is the appropriate word");
			}
			else if (temp.equalsIgnoreCase("search")){
				System.out.println("How would you like to search?(merge(m)/permutations(p)/dictionary trie(dt)) ");
				if (inputScanner.hasNext()){
					String searchType = inputScanner.next();
					if (searchType.equalsIgnoreCase("merge") || searchType.equalsIgnoreCase("m")){
						System.out.println(">");
						String sortedWord = dictIO.sortWord(inputScanner.next());
						ArrayList<HashMap<String,String>> listWords = dictionaryMap.get(sortedWord.substring(0, 1));
						boolean found = false;
						System.out.println("Anagrams of your search word were : ");
						for (HashMap<String,String> c :listWords){
							if (c.get(sortedWord) != null) {
								System.out.println(c.get(sortedWord));
								found = true;
							}
						}
						if (found == false) System.out.println("Sorry we could not find your word in the dictionary");
					}
					
				}
			}
			else {System.out.println("Sorry command was not recognized");}
		}




	}

}
